package cn.nyse.ktc_user.dao;

import cn.nyse.ktc_user.entity.Follow;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import cn.nyse.ktc_user.entity.User;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * @Description 用户 数据访问接口
 * @date 2020-10-14 17:34:42
*/
public interface UserDao extends JpaRepository<User,String>,JpaSpecificationExecutor<User>{

    User findByMobile(String mobile);

    @Query("update User u set u.fanscount=u.fanscount+?2 where u.id=?1")
    @Modifying
    void updateFansCount(String userid, Integer count);

    @Query("update User u set u.followcount=u.followcount+?2 where u.id=?1")
    @Modifying
    void updateFollowCount(String userid, Integer count);

    @Query("select u from User u left join Follow f on u.id=f.userid where f.userid=?1 ")
    User fino(String id);
}

